#include "musictableview.h"

#include <QMenu>
#include <QMouseEvent>
#include <QDebug>
#include <QHeaderView>
#include <QSettings>
MusicTableView::MusicTableView(QWidget *parent)
    :QTableView(parent)
{
    setWindowFlags(Qt::Window);
    setSelectionBehavior(QTableView::SelectRows);
    setSelectionMode(QAbstractItemView::SingleSelection);
    setWindowTitle("播放记录");
    setMinimumSize(400, 300);
    QSettings settings;
    settings.value("tableWidget/rect").isNull() ? setGeometry(1080, 200, 400, 300) : setGeometry(settings.value("tableWidget/rect").toRect());

//    QFont font;
//    font.setPointSize(10);
//    font.setFamily("Times New Roman");
//    horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
//    setFont(font);
}

void MusicTableView::removeMusic()
{
    QModelIndex current = currentIndex();
    model()->removeRow(current.row());
}

void MusicTableView::contextMenuEvent(QContextMenuEvent *event)
{
    QMenu menu;
    menu.addAction("删除歌曲", this, &MusicTableView::removeMusic);
    menu.exec(event->globalPos());
}
